package Servlet.User;

import Dao.DeleteBorrowBookDao;
import Dao.FindBookDao;
import Dao.UpdateNumBook;
import Table.Book;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/userGiveServlet")
public class UserGiveServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取图书的id
        String id = req.getParameter("id");
        int book_id = Integer.parseInt(id);
        Book book = FindBookDao.Find(book_id);
        int nums = book.getNums();
        //删除borrowbook的书
        DeleteBorrowBookDao.DeleteBorrowBook(book_id);
        //让book的数量加一
        UpdateNumBook.Update(book_id, nums);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
